<template>
  <el-form ref="formRef" :model="modelData" :rules="rules" label-width="100px">
    <el-form-item label="房产id" prop="detail[0].houseId" v-show="false">
      <el-input v-model="modelData.detail[0].houseId" placeholder="请输入房产id" />
    </el-form-item>
    <el-form-item label="房产名称" prop="detail[0].houseName">
      <el-input readonly v-model="modelData.detail[0].houseName" placeholder="请输入房产id" />
    </el-form-item>
    <el-form-item label="客户id" prop="detail[0].customerId">
      <el-input v-model="modelData.detail[0].customerId" placeholder="请输入客户id" />
    </el-form-item>
    <el-form-item label="设备id" prop="detail[0].equipId" v-show="false">
      <el-input disabled v-model="modelData.detail[0].equipId" placeholder="请输入设备id" />
    </el-form-item>
    <el-form-item label="设备名称" prop="detail[0].equipName">
      <el-input
        readonly
        v-model="modelData.detail[0].equipName"
        placeholder="请输入设备id"
      />
    </el-form-item>
    <el-form-item label="生效时间" prop="detail[0].effTime">
      <el-date-picker
        v-model="modelData.detail[0].effTime"
        type="date"
        value-format="x"
        placeholder="选择生效时间"
        class="!w-1/1"
      />
    </el-form-item>
    <el-form-item
      :label="props.busScope == '0' ? '行码' : props.busScope == '1' ? '表码' : '蒸汽量读数'"
      prop="detail[0].bv01"
    >
      <el-input v-model="modelData.detail[0].bv01" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="尖" prop="detail[0].bv02">
      <el-input v-model="modelData.detail[0].bv02" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="峰" prop="detail[0].bv03">
      <el-input v-model="modelData.detail[0].bv03" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="平" prop="detail[0].bv04">
      <el-input v-model="modelData.detail[0].bv04" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="谷" prop="detail[0].bv05">
      <el-input v-model="modelData.detail[0].bv05" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item label="备注" prop="detail[0].rem1">
      <el-input v-model="modelData.detail[0].rem1" placeholder="请输入备注" />
    </el-form-item>
  </el-form>
</template>
<script setup lang="ts">
const props = defineProps({
  busScope: {
    type: String,
    required: true
  }
})
const formRef = ref()
const rules = {
  'detail[0].equipId': [{ required: true, message: '设备id不能为空', trigger: 'blur' }],
  'detail[0].effTime': [{ required: true, message: '生效时间不能为空', trigger: 'blur' }],
  'detail[0].bv01': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[0].bv02': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[0].bv03': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[0].bv04': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[0].bv05': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[0].houseId': [{ required: true, message: '房产id不能为空', trigger: 'blur' }],
  'detail[0].customerId': [{ required: true, message: '客户id不能为空', trigger: 'blur' }]
}
// 创建本地数据副本
const modelData = defineModel<any>()

/** 表单校验 */
const validate = async () => {
  await formRef.value?.validate()
}
defineExpose({
  validate
})
</script>
